package com.four.commodity.service.impl;

import java.util.List;

import com.four.commodity.dao.CommodityDao;
import com.four.commodity.dao.impl.CommodityDaoImpl;
import com.four.commodity.pojo.Commodity;
import com.four.commodity.service.CommodityService;

public class CommodityServiceImpl implements CommodityService{

	@Override
	public List<Commodity> selectAll() {
		CommodityDao dao = new CommodityDaoImpl();
		return dao.selectAll();
	}
	
	public boolean login(String name,String id) {
		CommodityDao dao = new CommodityDaoImpl();
		Commodity c = dao.selectByName(name);
		if(c != null && c.getName().equals(name)&& c.getCategory_branch_id().equals(id)) {
			return true;
		}
		return false;
	}
	
	public Commodity selectById(String  id) {
		CommodityDao dao= new CommodityDaoImpl();
		int no = Integer.valueOf(id);
		return dao.selectById(no);
	}
	
	
	public boolean addCommodity(String id, String name,String producing_area,String descrption,String create_time,String market_price,String product_amount,String picture,String discount,String flag) {
		CommodityDao dao = new CommodityDaoImpl();
		int a = Integer.valueOf(id);
		int b = Integer.valueOf(flag);
		int n = dao.addCommodity(a, name, producing_area, descrption, create_time, market_price, product_amount, picture, discount,b);
		return n>0;
	}
	
	
	public boolean updateCommodity(String id, String name,String producing_area, String descrption,  String create_time,
			String market_price, String product_amount, String picture, String discount, String flag) {
		CommodityDao dao = new CommodityDaoImpl();
		int a = Integer.valueOf(id);
		int b = Integer.valueOf(flag);
		int n = dao.updateCommodity(a,name, producing_area, descrption,  product_amount,create_time, market_price, picture, discount,b);
		return n>0;
	}
	
	public boolean deleteCommodity(String id) {
		CommodityDao dao = new CommodityDaoImpl();
		int i =Integer.valueOf(id);
		int n = dao.deleteCommodity(i);
		return n>0;
	}


		
}